import request from '@/utils/request'

const api = {
  user: '/user',
  role: '/role',
  service: '/service',
  permission: '/permission',
  permissionNoPager: '/permission/no-pager',
  orgTree: '/org/tree',
  configs: '/api/configs',
  departments: '/api/departments',
  member: '/api/members',
  record: '/api/records',
  customer: '/api/customers',
  delivery: '/api/delivery-stations',
  setting: '/api/settings',
  areaTree: '/api/districts/tree',
  area: '/api/districts',
  deliveryDetail: '/api/delivery-detail',
  stationRecord: '/api/delivery-records',
  deliveries: '/api/deliveries',
  wbOrder: '/api/wb-orders',
  syncDeliveryStation: '/api/delivery-stations/sync',
  syncDeliveryDetail: '/api/delivery-detail/sync',
  syncOrder: '/api/records/sync',
  AdministrativeRegion: '/api/districts',
  currentUser: '/api/members/author'
}

export default api

export function getWBOrderLists (parameter) {
  return request({
    url: api.wbOrder,
    method: 'get',
    params: parameter
  })
}

export function getDeliverylies (id) {
  return request({
    url: api.deliveries + '/' + id,
    method: 'get'
  })
}

export function getDeliveriesLists (parameter) {
  return request({
    url: api.deliveries,
    method: 'get',
    params: parameter
  })
}

export function deleteDeliveries (id) {
  return request({
    url: api.deliveries + '/' + id,
    method: 'delete'
  })
}

export function putDeliveries (id, parameter) {
  return request({
    url: api.deliveries + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addDeliveries (parameter) {
  return request({
    url: api.deliveries,
    method: 'post',
    data: parameter
  })
}

export function getStationRecord (params) {
  return request({
    url: api.stationRecord,
    method: 'get',
    params: params
  })
}

export function getStationRecordLists (parameter) {
  return request({
    url: api.stationRecord,
    method: 'get',
    params: parameter
  })
}

export function deleteStationRecord (id) {
  return request({
    url: api.stationRecord + '/' + id,
    method: 'delete'
  })
}

export function putStationRecord (id, parameter) {
  return request({
    url: api.stationRecord + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addStationRecord (parameter) {
  return request({
    url: api.stationRecord,
    method: 'post',
    data: parameter
  })
}

export function getDeliveryDetailLists (parameter) {
  return request({
    url: api.deliveryDetail,
    method: 'get',
    params: parameter
  })
}

export function deleteDeliveryDetail (id) {
  return request({
    url: api.deliveryDetail + '/' + id,
    method: 'delete'
  })
}

export function putDeliveryDetail (id, parameter) {
  return request({
    url: api.deliveryDetail + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addDeliveryDetail (parameter) {
  return request({
    url: api.deliveryDetail,
    method: 'post',
    data: parameter
  })
}

export function getAreaTreeLists (parameter) {
  return request({
    url: api.areaTree,
    method: 'get',
    params: parameter
  })
}

export function getArea (id) {
  return request({
    url: api.area + '/' + id,
    method: 'get'
  })
}

export function getAreaLists (parameter) {
  return request({
    url: api.area,
    method: 'get',
    params: parameter
  })
}

export function deleteArea (id) {
  return request({
    url: api.area + '/' + id,
    method: 'delete'
  })
}

export function putArea (id, parameter) {
  return request({
    url: api.area + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addArea (parameter) {
  return request({
    url: api.area,
    method: 'post',
    data: parameter
  })
}

export async function getSettingLists (parameter) {
  return request({
    url: api.setting,
    method: 'get',
    params: parameter
  })
}

export function deleteSetting (id) {
  return request({
    url: api.setting + '/' + id,
    method: 'delete'
  })
}

export function putSetting (id, parameter) {
  return request({
    url: api.setting + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addSetting (parameter) {
  return request({
    url: api.setting,
    method: 'post',
    data: parameter
  })
}

export function getCustomerLists (parameter) {
  return request({
    url: api.customer,
    method: 'get',
    params: parameter
  })
}

export function deleteCustomer (id) {
  return request({
    url: api.customer + '/' + id,
    method: 'delete'
  })
}

export function putCustomer (id, parameter) {
  return request({
    url: api.customer + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addCustomer (parameter) {
  return request({
    url: api.customer,
    method: 'post',
    data: parameter
  })
}

export function getDeliveryLists (parameter) {
  return request({
    url: api.delivery,
    method: 'get',
    params: parameter
  })
}

export function deleteDelivery (id) {
  return request({
    url: api.delivery + '/' + id,
    method: 'delete'
  })
}

export function putDelivery (id, parameter) {
  return request({
    url: api.delivery + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addDelivery (parameter) {
  return request({
    url: api.delivery,
    method: 'post',
    data: parameter
  })
}

export function getRecord (id) {
  return request({
    url: api.record + '/' + id,
    method: 'get'
  })
}

export function getRecordLists (parameter) {
  return request({
    url: api.record,
    method: 'get',
    params: parameter
  })
}

export function deleteRecord (id) {
  return request({
    url: api.record + '/' + id,
    method: 'delete'
  })
}

export function putRecord (id, parameter) {
  return request({
    url: api.record + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addRecord (parameter) {
  return request({
    url: api.record,
    method: 'post',
    data: parameter
  })
}

export function getMember (id) {
  return request({
    url: api.member + '/' + id,
    method: 'get'
  })
}

export function getMemberLists (parameter) {
  return request({
    url: api.member,
    method: 'get',
    params: parameter
  })
}

export function deleteMember (id) {
  return request({
    url: api.member + '/' + id,
    method: 'delete'
  })
}

export function putMember (id, parameter) {
  return request({
    url: api.member + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addMember (parameter) {
  return request({
    url: api.member,
    method: 'post',
    data: parameter
  })
}

export function getDepartmentsLists (parameter) {
  return request({
    url: api.departments,
    method: 'get',
    params: parameter
  })
}

export function deleteDepartment (id) {
  return request({
    url: api.departments + '/' + id,
    method: 'delete'
  })
}

export function putDepartment (id, parameter) {
  return request({
    url: api.departments + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addDepartment (parameter) {
  return request({
    url: api.departments,
    method: 'post',
    data: parameter
  })
}

export function putDepartmentSetting (departmentId, data) {
  return request({
    url: api.departments + '/' + departmentId + '/config',
    method: 'put',
    data: data
  })
}

export function getConfigLists (parameter) {
  return request({
    url: api.configs,
    method: 'get',
    params: parameter
  })
}

export function deleteConfig (id) {
  return request({
    url: api.configs + '/' + id,
    method: 'delete'
  })
}

export function putConfig (id, parameter) {
  return request({
    url: api.configs + '/' + id,
    method: 'put',
    data: parameter
  })
}

export function addConfig (parameter) {
  return request({
    url: api.configs,
    method: 'post',
    data: parameter
  })
}

export function getUserList (parameter) {
  return request({
    url: api.user,
    method: 'get',
    params: parameter
  })
}

export function getRoleList (parameter) {
  return request({
    url: api.role,
    method: 'get',
    params: parameter
  })
}

export function getServiceList (parameter) {
  return request({
    url: api.service,
    method: 'get',
    params: parameter
  })
}

export function getPermissions (parameter) {
  return request({
    url: api.permissionNoPager,
    method: 'get',
    params: parameter
  })
}

export function getOrgTree (parameter) {
  return request({
    url: api.orgTree,
    method: 'get',
    params: parameter
  })
}

// id == 0 add     post
// id != 0 update  put
export function saveService (parameter) {
  return request({
    url: api.service,
    method: parameter.id === 0 ? 'post' : 'put',
    data: parameter
  })
}

export function saveSub (sub) {
  return request({
    url: '/sub',
    method: sub.id === 0 ? 'post' : 'put',
    data: sub
  })
}

// Sync Datas
export function syncDeliveryStation () {
  // 投递站
  return request({
    url: api.syncDeliveryStation,
    method: 'post'
  })
}

export function syncDeliveryDetail () {
  return request({
    url: api.syncDeliveryDetail,
    method: 'post'
  })
}

export function syncOrder () {
  return request({
    url: api.syncOrder,
    method: 'post'
  })
}

export function getAdministrativeRegionList (parameter) {
  return request({
    url: api.AdministrativeRegion,
    method: 'get',
    params: parameter
  })
}

export function getCurrentUser () {
  return request({
    url: api.currentUser,
    method: 'get'
  })
}
